package cn.wolfcode.util;

import cn.wolfcode.domain.Department;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

//查询结果
@Getter
@Setter
public class PageResult<T> {
    //上一页
    private int prevPage;
    //下一页
    private int nextPage;
    //每页显示多少
    private int pageSize;
    //跳转到x页，当前页
    private int currentPage;
    //总页
    private int totalPage;
    //总数据数
    private int totalCount;
    //结果集
    private List<T> data;

    public PageResult(int pageSize, int currentPage, int totalCount, List<T> data) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.totalCount = totalCount;
        this.data = data;
        if (totalCount <= pageSize) {
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
        }
        //计算
        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage - 1 > 0 ? currentPage - 1 : 1;
        this.nextPage = currentPage + 1 < totalPage ? currentPage + 1 : totalPage;
    }
}
